<template>
  <div class="post-wrapper">
    <div class="post-content-wrapper">
      <div class="person-wrapper">
        <div class="louzhu">楼主</div>
        <div class="nick-name-text">
          <a href="javascript:void(0)">{{thread.nickName}}</a>
        </div>
        <div class="person-img"></div>
      </div>
      <div class="content-wrapper">
        <h1 class="content-title">{{thread.title}}</h1>
        <div class="some-things">
          <span class="write-time-text">楼主 发表于 {{thread.createTime}}</span>
          <div class="query-param-click">
            <a href="javascript:void(0)">只看楼主</a>
            <a href="javascript:void(0)">倒叙查看</a>
          </div>
        </div>
        <div class="content">{{thread.content}}</div>
        <div class="content-footer">
          <a href="javascript:void(0)">回复</a>
          <a href="javascript:void(0)">点赞个数</a>
        </div>
      </div>
    </div>
    <div class="post-content-wrapper" v-for="post in posts">
      <div class="person-wrapper">
        <div class="nick-name-text">
          <a href="javascript:void(0)">{{post.nickName}}</a>
        </div>
        <div class="person-img"></div>
      </div>
      <div class="content-wrapper">
        <h1 class="content-title">{{post.title}}</h1>
        <div class="some-things">
          <span class="write-time-text">{{post.nickName}} 发表于 {{post.createTime}}</span>
        </div>
        <div class="content">{{post.replyContent}}</div>
        <div class="content-footer">
          <a href="javascript:void(0)">回复</a>
          <a href="javascript:void(0)">点赞个数</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import { GET_POST_BY_THREAD_ID_URL } from '../../../common/js/url'
  import { formatDateToString } from '../../../common/js/dateUtils'
  export default {
    data () {
      return {
        posts: [],
        thread: this.$route.query
      }
    },
    mounted: function () {
      this.getPostsByThreadGroup()
    },
    methods: {
      getPostsByThreadGroup () {
        let param = {
          threadId: this.thread.id
        }
        this.$http.get(GET_POST_BY_THREAD_ID_URL(this.thread.id), {params: param}).then(response => {
          this.posts = response.data.data.map(data => {
            data.createTime = formatDateToString(new Date(data.createTime), 'yyyy-MM-dd hh:mm:ss')
            return data
          })
        })
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  @import "post.styl";
</style>
